package util;

import java.awt.Color;

import processing.core.PApplet;

/**
 * Represent a pickeable point.
 * @author Juan Camilo Ibarra
 *
 */
public class VAPoint extends PickeableObject{

	private int id;
	private int posX;
	private int posY;
	private int color;
	public int size = 5;

	/**
	 * Basic constructor
	 * @param posX position X in pixels of the point
	 * @param posY position Y in pixels of the point
	 * @param mainApplet
	 */
	public VAPoint(int posX, int posY,PApplet mainApplet)
	{
		super(mainApplet);
		this.posX = posX;
		this.posY = posY;
		this.id = 0;
		this.color = Color.BLACK.getRGB();
	}
	/**
	 * 
	 * @param size
	 */
	public void setSize(int size)
	{
		this.size = size;
	}
	/**
	 * 
	 * @param id
	 */
	public void setId(int id)
	{
		this.id = id;
	}
	/**
	 * 
	 * @return
	 */
	public int getId() {
		return id;
	}

	/**
	 * Returns if the mouse is over the point
	 * @return
	 */
	public boolean mouseIsOver (){
		float disX = posX - mainApplet.mouseX;
		float disY = posY - mainApplet.mouseY;

		if((int)(PApplet.sqrt(PApplet.sq(disX) + PApplet.sq(disY))) < size) {
			return true;
		}else{
			return false;
		}
	}

	/**
	 * 
	 * @return the X position in pixels
	 */
	public int getPosX() {
		return posX;
	}

	/**
	 * 
	 * @return the Y position in pixels
	 */
	public int getPosY() {
		return posY;
	}

	/**
	 * Sets the color of the point
	 * @param currentColor
	 */
	public void setColor(int currentColor) {
		color = currentColor;
	}
	/**
	 * Draw the point only if it is necessary (if the state has changed)
	 */
	public void drawPoint()
	{
		if(changed)
		{
			int pointSize = size;
			mainApplet.fill(color);
			mainApplet.stroke(color);
			if(isSelected())
			{
				pointSize *= 2;
			}
			mainApplet.ellipse (posX, posY, pointSize, pointSize);
			changed = false;
		}
	}
	public void setChanged()
	{
		changed = true;
	}
}
